<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="description" content="Filtrify">
        <meta name="keywords" content="javascript, jquery, lazy load, performance, plugin" />
        <meta name="author" content="Luís Almeida">
        <meta name="viewport" content="width=device-width">
        <title>jQuery Unveil - A very lightweight plugin to lazy load images</title>
    </head>

    <style>

    body {
        background: #FFF;
        color: #555;
        font-family: "Helvetica Neue", sans-serif;
        font-weight: 300;
        line-height: 1.7;
        padding: 30px 30px 300px 30px;
        margin: 0 auto;
        max-width: 480px;
    }
    header {
        margin: 100px 0;
    }
    header p {
        color: #CCC;
        margin: 0 0 25px 0;
    }
    header h1 {
        color: #000;
        font-size: 75px;
        line-height: 1;
        margin: 0 0 10px 0;
    }
    header h1 small{
        font-size: 16px;
    }
    h2 {
        color: #333;
        margin-top: 100px;
        font-size: 1em;
    }
    p {
        margin: 15px auto;
    }
    a {
        color: #3595b5;
    }
    strong {
        font-size: 1.5em;
        color: #CCC;
    }
    code {
    }
    code > span.red {
        color: #D14;
    }
    code > span.blue {
        color: #099;
    }
    code > span.purple {
        color: #C0C;
    }
    ul {
        list-style: none;
        padding: 0;
    }
    ul > li {
        margin-top: 50px;
        text-align: center;
    }
    ul > li > img {
        display: inline-block;
        max-width: 100%;
    }

    .twitter-share-button {
        margin-left: 20px;
    }

    </style>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="jquery-1.9.1.min.js"><\/script>')</script>
    <script src="jquery.unveil.js"></script>

    <script>
    $(function() {
        $("li img").unveil(300);
    });
    </script>

    <body>

    <header>
        <h1>Unveil<small>.js</small></h1>
        <p>A very lightweight plugin to lazy load images for jQuery or Zepto.js</p>

        <iframe src="http://ghbtns.com/github-btn.html?user=luis-almeida&repo=unveil&type=watch" allowtransparency="true" frameborder="0" scrolling="0" width="55" height="20"></iframe>
        <iframe src="http://ghbtns.com/github-btn.html?user=luis-almeida&repo=unveil&type=fork" allowtransparency="true" frameborder="0" scrolling="0" width="55" height="20"></iframe>
        <a href="https://twitter.com/share" class="twitter-share-button" data-text="unveil.js - A very lightweight plugin to lazy load images" data-via="lmgalmeida" data-related="lmgalmeida" data-count="none">Tweet</a>
    </header>

    <p>Most of us are familiar with the <a target="_blank" href="http://www.appelsiini.net/projects/lazyload">Lazy Load</a> plugin by <a target="_blank" href="http://www.appelsiini.net/">Mika Tuupola</a>.
    <p>This plugin is very useful and it boosts performance delaying loading of images in long web pages because images outside of viewport (visible part of web page) won't be loaded until the user scrolls to them.</p>
    <p>Lazy Load has some cool options such as custom effects, container, events or data attribute. If you're not gonna use any of them you can reduce the file size by leaving just the essential code to show the images.</p>
    <p>That's what I did and this is my lightweight version of Lazy Load with support for serving high-resolution images to devices with retina displays - <strong>less than 1k</strong>.</p>

    <h2>Usage</h2>
    <p>Use a placeholder image in the src attribute - something to be displayed while the original image loads - and include the actual image source in a "data-src" attribute.</p>
    <p>If you want to serve high-resolution images to devices with retina displays, you just have to include the source for those images in a "data-src-retina" attribute.</p>
    <p>You don't need to include a "data-src-retina" attribute in all the image tags, unveil is smart enough to fallback to "data-src" or even do nothing in case there isn't any "data-src" specified.</p>
    <code>&lt;img <span class="blue">src=</span><span class="red">"bg.png"</span> <span class="blue">data-src=</span><span class="red">"img1.jpg"</span> /></code>
    <br>
    <code>&lt;img <span class="blue">src=</span><span class="red">"bg.png"</span> <span class="blue">data-src=</span><span class="red">"img2.jpg"</span> <span class="blue">data-src-retina=</span><span class="red">"img2-retina.jpg"</span> /></code>
    <br>
    <p>If you care about users without javascript enabled, you can include the original image inside a &lt;noscript&gt; tag:</p>
    <code>&lt;noscript&gt;<br>&nbsp;&nbsp;&lt;img <span class="blue">src=</span><span class="red">"img1.jpg"</span> /><br>&lt;/noscript&gt;</code>
    <br><br>
    <p>Run the script on document ready:</p>
    <code>$(<span class="blue">document</span>).ready(<span class="blue">function</span>() {<br>
    &nbsp;&nbsp;$(<span class="red">"img"</span>).unveil();<br>
    });</code>

    <h2>Threshold</h2>
    <p>By default, images are only loaded and "unveiled" when the user scrolls to them and they became visible on the screen.</p>
    <p>If you want your images to load earlier than that, lets say 200px before they appear on the screen, you just have to:</p>
    <code>$(<span class="red">"img"</span>).unveil(<span class="purple">200</span>);</code>

    <h2>Callback</h2>
    <p>As a second parameter you can also specify a callback function that will fire after an image as been "unveiled".</p>
    <p>Inside the callback function <code>this</code> refers to the image's DOM node, so with the help of CSS3 (or jQuery animations) and by attaching a simple load event you can easily add some fancy entrance animation to your images:</p>
    <code><span class="blue">img</span> {<br>
    &nbsp;&nbsp;opacity: 0;<br>
    &nbsp;&nbsp;transition: opacity .3s ease-in;<br>
    }</code>
    <br><br>
    <code>$(<span class="red">"img"</span>).unveil(<span class="purple">200</span>, <span class="blue">function</span>() {<br>
    &nbsp;&nbsp;$(this).load(<span class="blue">function</span>() {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;this.style.opacity = 1;<br>
    &nbsp;&nbsp;});<br>
    });</code>

    <h2>Trigger</h2>
    <p>You can still trigger image loading whenever you need.</p>
    <p>All you have to do is select the images you want to "unveil" and trigger the event:</p>
    <code>$(<span class="red">"img"</span>).trigger(<span class="red">"unveil"</span>);</code>

    <h2>Demo</h2>
    <p>The images were taken from the The Fox is Black <a href="http://www.thefoxisblack.com/category/the-desktop-wallpaper-project/">Desktop Wallpaper Project</a> - cool stuff!</p>
    <p>If you're on a "normal" display, unveil will load the low resolution version (800x500). In case you're on a device with a retina display, the high resolution version (1280x800 in this case) will be loaded instead.</p>
    <p>Scroll down to see it working.</p>

    <ul>
        <li><img src="img/loader.gif" data-src="img/anti-bullying-tom-froese-wallpaper-800x500.jpg" data-src-retina="img/anti-bullying-tom-froese-wallpaper-1280x800.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/brock-davis-wallpaper-800x500.jpg" data-src-retina="img/brock-davis-wallpaper-1280x800.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/dark-igloo-wallpaper-800x500.jpg" data-src-retina="img/dark-igloo-wallpaper-800x500.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/dark-igloo-wallpaper-1-800x500.jpg" data-src-retina="img/dark-igloo-wallpaper-1-800x500.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/iceland-smojr-wallpaper-800x500.jpg" data-src-retina="img/iceland-smjor-wallpaper-1280x800.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/james-olstein-wallpaper-800x500.jpg" data-src-retina="img/james-olstein-wallpaper-1280x800.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/johanna-basford-wallpaper-800x500.jpg" data-src-retina="img/johanna-basford-wallpaper-1280x800.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/Jude_Landry_Wallpaper_800x500.jpg" data-src-retina="img/Jude_Landry_Wallpaper_1280x800.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/julieta-felix-wallpaper-800x500.jpg" data-src-retina="img/julieta-felix-wallpaper-1280x800.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/Timothy-J-Reynolds-wallpaper-800x500.jpg" data-src-retina="img/Timothy-J-Reynolds-wallpaper-1280x800.jpg" /></li>
        <li><img src="img/loader.gif" data-src="img/haik-avanian-wallpaper-800x500.jpg" data-src-retina="img/haik-avanian-wallpaper-1280x800.jpg" /></li>
    </ul>

    <h2>Browser support</h2>
    <p>Compatible with All Browsers and IE7+.</p>

    <h2>Download</h2>
    <p>Download the script from the project page on <a href="https://github.com/luis-almeida/unveil">GitHub</a>.</p>
    <p>If you have any suggestion or bug to report please use github issues or get it touch with me on twitter - <a href="https://twitter.com/lmgalmeida">@lmgalmeida</a>.</p>

    <h2>License</h2>
    <p>Unveil is licensed under the <a href="http://opensource.org/licenses/MIT">MIT license</a>.</p>

    <script>
    // Twitter
    !function(d,s,id){
        var js,fjs=d.getElementsByTagName(s)[0];
        if(!d.getElementById(id)){
            js=d.createElement(s);
            js.id=id;
            js.src="//platform.twitter.com/widgets.js";
            fjs.parentNode.insertBefore(js,fjs);
        }
    }(document,"script","twitter-wjs");
    // Analytics
    var _gaq=[['_setAccount','UA-30936310-1'],['_trackPageview']];
    (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
    g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
    s.parentNode.insertBefore(g,s)}(document,'script'));
    </script>

    </body>
</html>
